package com.scanner.barcodereceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import com.scanner.barcodeservice.SerialPortService;
import com.scanner.bean.ScanSetting;
import com.scanner.util.BaseUtils;
import com.scanner.util.LogUtil;

public class BootBroadcastReceiver extends BroadcastReceiver {

	private boolean isStart = false;
	@Override
	public void onReceive(Context context, Intent intent) {
		LogUtil.v("开机自启===action=======" + intent.getAction());
		String action = intent.getAction();
		if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
			ScanSetting settingFormShare = BaseUtils.getSettingFormShare();
			if(settingFormShare.getScanModule() > 0  && settingFormShare.getScanModule() < 5){//表示已经做出了选择。进入了扫描界面
				if(settingFormShare.getOpenService_reboot()){
					//开机时不自动启动该app，进入该app时启动
					intent = new Intent(context,SerialPortService.class);
					if(Build.VERSION.SDK_INT>Build.VERSION_CODES.N_MR1){
						context.startForegroundService(intent);
					}else {
						context.startService(intent);
					}
				}
			}

		}
	}

}
